package net.sf.midollo.io.lcdui.textbox;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.microedition.lcdui.TextBox;

import net.sf.midollo.io.IOStream;

public class TextBoxIOStream implements IOStream {

  protected TextBoxInputStream is;
  protected TextBoxOutputStream os;

  public TextBoxIOStream(TextBox textBox) {
    this(textBox, textBox);
  }

  public TextBoxIOStream(TextBox inputTextBox, TextBox outputTextBox) {
    this.is = new TextBoxInputStream(inputTextBox);
    this.os = new TextBoxOutputStream(outputTextBox);
  }

  public void acceptInput() {
    this.is.accept();
  }

  public InputStream getInput() throws IOException {
    return this.is;
  }

  public OutputStream getOutput() throws IOException {
    return this.os;
  }

  public void close() throws IOException {
    try {
      this.is.close();
    } finally {
      this.os.close();
    }
  }
}
